package com.jcrj.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	public static Date FormDate(String time) {
		Date data = null;
		if ((time != null) && (!"".equals(time))) {
			DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			try {
				data = format.parse(time);
			} catch (ParseException e) {
				e.printStackTrace();
				return data;
			}
		}
		return data;
	}

	public static String DateToString(Date date) {
		String time = null;
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		if ((date != null) && (!"".equals(date))) {
			time = format.format(date);
		}
		return time;
	}

	public static String DateToFormat(Date date) {
		String time = null;
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if ((date != null) && (!"".equals(date))) {
			time = format.format(date);
		}
		return time;
	}

	public static String dateFirstDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		int year = c.get(1);
		int month = c.get(2);
		return year + "-" + (month + 1) + "-" + 1;
	}

	public static String dateLastDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(5, 1);
		c.roll(5, -1);
		int year = c.get(1);
		int month = c.get(2);
		int maxDate = c.get(5);
		return year + "-" + (month + 1) + "-" + maxDate;
	}

	public static String getYear() {
		DateFormat format = new SimpleDateFormat("yyyy");
		return format.format(new Date());
	}

	public static String getNowDateWeek() {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		return "" + calendar.get(7);
	}

	public static String getNowDateDay() {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		return "" + calendar.get(5);
	}

	public static long maxMunites(int hour, int munite, double alertTime) {
		int phoneTime = (int) (alertTime * 60.0D);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		Calendar calendar2 = Calendar.getInstance();
		calendar2.setTime(new Date());
		calendar2.set(11, hour);
		calendar2.set(12, munite);
		calendar2.set(13, 0);
		calendar2.add(12, -phoneTime);
		long second = calendar.getTime().getTime() - calendar2.getTime().getTime();
		return second / 1000L / 60L;
	}

	public static String getYearFirstDay(int year) {
		return year + "-" + "01-01";
	}

	public static String getYearLastDay(int year) {
		return year + "-" + "12-31";
	}
}

/*
 * Location: /Volumes/work/oa/WEB-INF/classes/ Qualified Name:
 * com.jcrj.util.DateUtil JD-Core Version: 0.6.0
 */